package com.ldx.lock8;

import java.util.concurrent.TimeUnit;

public class Test4 { public static void main(String[] args) {
    Phone4 phone1 = new Phone4();
    Phone4 phone2 = new Phone4();
    new Thread(()-> {
        phone1.sendSms();
    },"A").start();

    try {
        TimeUnit.SECONDS.sleep(1);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    new Thread(()-> {
        phone2.call();
    },"B").start();
}
}

class Phone4 {
    //synchronized 锁的对象是方法的调用者
    //两个方法用的同一个锁，谁先拿到谁先执行
    public static synchronized void sendSms() {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("sendSms");
    }

    public  synchronized void call() {
        System.out.println("call");
    }

}